package tech.runchen.gz5055.oms.modules.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import tech.runchen.gz5055.oms.common.utils.MapUtils;
import tech.runchen.gz5055.oms.modules.system.entity.OrderDetailEntity;
import tech.runchen.gz5055.oms.modules.system.mapper.OrderDetailMapper;
import tech.runchen.gz5055.oms.modules.system.service.IOrderDetailService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 订单明细表 服务实现类
 * </p>
 *
 * @author zzj
 * @since 2023-10-10
 */
@Service
public class OrderDetailServiceImpl extends ServiceImpl<OrderDetailMapper, OrderDetailEntity> implements IOrderDetailService {

    @Override
    public void saveOrderDetailBatch(Long orderId, List<OrderDetailEntity> orderDetailList) {
        if (orderDetailList == null || orderDetailList.size() == 0) {
            return;
        }
        for (OrderDetailEntity orderDetail : orderDetailList) {
            orderDetail.setOrderId(orderId);
            this.save(orderDetail);
        }
    }

    @Override
    public List<OrderDetailEntity> queryOrderDetailList(Long orderId) {
        return this.list(new QueryWrapper<OrderDetailEntity>().eq("order_id", orderId));
    }

    @Override
    public void deleteByOrderIdBatch(Long orderId) {
        this.removeByMap(new MapUtils().put("order_id", orderId));
    }
}
